package com.ph.irp.base.currency.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.currency.service.CurrencyService;
import com.ph.irp.model.PBaseCurrency;

public class CurrencyAction extends ActionSupport {
	private String FORWARD = null;

	private List<PBaseCurrency> currencyList = null;

	private Object[] rowlist;

	private PBaseCurrency currencyModel = null;

	private CurrencyService currencyService;

	private String successString;
	
	private List<Integer> list = new ArrayList<Integer>();

	public List<PBaseCurrency> getCurrencyList() {
		return currencyList;
	}

	public void setCurrencyList(List<PBaseCurrency> currencyList) {
		this.currencyList = currencyList;
	}

	public CurrencyService getCurrencyService() {
		return currencyService;
	}

	public void setCurrencyService(CurrencyService currencyService) {
		this.currencyService = currencyService;
	}
	
	/*
	 * 查询所有数据
	 */
	public String showCurrencyList() throws Throwable{
		currencyModel = null;
		currencyList = currencyService.getCurrencyAllList(currencyModel);
		if(currencyList!=null)
			FORWARD = "success";
		else
			FORWARD = "input";
		return FORWARD;
	}
	
	/*
	 * 打开新增页面
	 */
	public String showAddCurrency(){
		currencyModel = null;
		FORWARD = "success";
		return FORWARD;
	}
	
	/*
	 * 打开修改页面
	 */
	public String showEditCurrency() throws Throwable{
		currencyModel = currencyService.getCurrencyByID(Integer
				.valueOf((String) rowlist[0]));
		if(currencyModel!=null)
			FORWARD = "success";
		else
			FORWARD = "input";
		return FORWARD;
	}
	
	/*
	 * 新增
	 */
	public String addCurrency() throws Throwable{
		currencyService.addCurrency(currencyModel);
		currencyModel = null;
		FORWARD = "success";
		return FORWARD;
	}
	
	/*
	 * 修改
	 */
	public String editCurrency() throws Throwable{
		currencyService.updateCurrency(currencyModel);
		currencyModel = null;
		FORWARD = "success";
		return FORWARD;
	}
	
	/*
	 * 查询
	 */
	public String getCurrency() throws Throwable{
		FORWARD = "success";
		if(currencyModel.getCurrencyName()!=null && currencyModel.getCurrencyCode()!=null){
			currencyList = currencyService.getCurrencyByCodeAndName(currencyModel.getCurrencyCode(), currencyModel.getCurrencyName());
		}else if(currencyModel.getCurrencyCode()!=null){
			currencyList = currencyService.getCurrencyByCode(currencyModel.getCurrencyCode());
		}else if(currencyModel.getCurrencyName()!=null){
			currencyList = currencyService.getCurrencyByName(currencyModel.getCurrencyName());
		}else{
			FORWARD = "input";
		}
		currencyModel = null;
		return FORWARD;
	}
	
	
	/*
	 * 删除币别
	 */
	public String deleteCurrency() throws Throwable{
		for(int i=0;i<rowlist.length;i++){
			currencyService.delectCurrency(Integer.parseInt((String) rowlist[i]));
		}
		FORWARD = "success";
		return FORWARD;
	}
	
	
	/*
	 * 打开币别选择页面
	 */
	public String selectCurrency() throws Throwable {

		currencyList = currencyService.getCurrencyAllList(currencyModel);
		currencyModel = null;
		FORWARD = "success";
		return FORWARD;
	}

//	/*
//	 * 增加数据
//	 */
//	public String add() throws Throwable {
//		if (currencyModel.getCurrencyId() != 0) {
//			currencyService.updateCurrency(currencyModel);
//			currencyModel = null;
//		} else {
//			currencyService.addCurrency(currencyModel);
//			currencyModel = null;
//		}
//		FORWARD = "display";
//		return FORWARD;
//
//	}
//
//
//	/*
//	 * 修改币别
//	 */
//	public String update() throws Throwable {
//		currencyModel = currencyService.getCurrencyByID(Integer
//				.valueOf((String) rowlist[0]));
//		FORWARD = "addInput";
//		return FORWARD;
//	}
//
//	/*
//	 * 删除记录
//	 */
//	public String delete() throws Throwable {
//
//		int result = 0;
//		for (int i = 0; i < rowlist.length; i++) {
//			result = currencyService.delectCurrency(Integer
//					.valueOf((String) rowlist[i]));
//		}
//		if (result == 1) {
//			FORWARD = "display";
//		} else {
//			setSuccessString("不存在该币别");
//			FORWARD = "error";
//		}
//		return FORWARD;
//
//	}
//
//	public PBaseCurrency getCurrencyModel() {
//		return currencyModel;
//	}
//
//	public void setCurrencyModel(PBaseCurrency currencyModel) {
//		this.currencyModel = currencyModel;
//	}


	public Object[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}

	public List<Integer> getList() {
		return list;
	}

	public void setList(List<Integer> list) {
		this.list = list;
	}

	public String getSuccessString() {
		return successString;
	}

	public void setSuccessString(String successString) {
		this.successString = successString;
	}

//	public String getCurrencyName() {
//		return currencyName;
//	}
//
//	public void setCurrencyName(String currencyName) {
//		this.currencyName = currencyName;
//	}
//
//	public String getCurrencyCode() {
//		return currencyCode;
//	}
//
//	public void setCurrencyCode(String currencyCode) {
//		this.currencyCode = currencyCode;
//	}

	public PBaseCurrency getCurrencyModel() {
		return currencyModel;
	}

	public void setCurrencyModel(PBaseCurrency currencyModel) {
		this.currencyModel = currencyModel;
	}

}
